package logic

import (
	"context"
	"shell/houserpc/houserpc"
	"shell/houserpc/internal/svc"
	"shell/models/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type SeekListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSeekListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SeekListLogic {
	return &SeekListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SeekListLogic) SeekList(in *houserpc.SeekListRequest) (*houserpc.SeekListResponse, error) {
	// todo: add your logic here and delete this line
	var seeks []mysql.Seek

	mysql.DB.Debug().Order("created_at desc").Find(&seeks)

	var seekList []*houserpc.SeekList
	for _, seek := range seeks {
		list := houserpc.SeekList{
			UserId:  seek.UserId,
			HouseId: seek.HouseId,
			Context: seek.Context,
		}
		seekList = append(seekList, &list)
	}

	return &houserpc.SeekListResponse{
		List: seekList,
	}, nil
}
